package ioperations;

import book.Book;
import book.BookList;

import javax.xml.namespace.QName;
import java.util.Scanner;

public class DelOperation implements IOPeration{
    public void work(BookList bookList){
        System.out.println("删除图书");
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入你想要删除的图书");
        String name= scanner.next();
        int currentSise= bookList.getUsedSize();
        int pos=-1;
        int i=0;
        for (; i <currentSise ; i++) {
            Book book =bookList.getBook(i);
            if(book.getName().equals(name)){
                pos=i;
                break;
            }
        }
        if(i==currentSise){
            System.out.println("没有你要删除的书");
            return;
        }
        for (int j = pos; j <currentSise-1 ; j++) {
            Book book=bookList.getBook(j+1);
            bookList.setBook(j,book);
        }
        bookList.setBook(currentSise-1,null);
        bookList.setUsedSize(currentSise-1);
        System.out.println("删除成功");
    }
}
